﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using PreguntaAlExperto.DataFramework;
using PreguntaAlExperto.RulesLayer.Entities;
using PreguntaAlExperto.TransporterObjectsFramework;
using PreguntaAlExperto.RulesLayer.ObjectMapper.Contracts;
using PreguntaAlExperto.RulesLayer.Services;

namespace PreguntaAlExperto.ObjectMapper.DTO
{
    internal class AskExpertDTO
        : BaseDTO
    {
        public object Select(string query, SearchCriteria searchCriteria)
        {
            DataAccess dataAccess = new DataAccess();
            BaseList<AskNode> _transporter = new BaseList<AskNode>();

            foreach (object rawEntity in dataAccess.Select(query, searchCriteria))
            {
                AskNode _node = new AskNode();

                /* tblPublisher.LastLogin, tblPublisher.AccountActivated*/
                _node.Ask_ID = int.Parse(((ArrayList)rawEntity)[0].ToString());
                _node.Topic = ((ArrayList)rawEntity)[1].ToString();
                _node.Comment_Body = ((ArrayList)rawEntity)[2].ToString();
                _node.Comment_Date = (DateTime)((ArrayList)rawEntity)[3];
                _node.AllowedToComment = (bool)((ArrayList)rawEntity)[4];
                _node.AllowedToView = (bool)((ArrayList)rawEntity)[5];
                _node.ParentNode = int.Parse(((ArrayList)rawEntity)[6].ToString());

                Publisher _publisher = new Publisher();
                _publisher.ID_Publisher = int.Parse(((ArrayList)rawEntity)[7].ToString());
                _publisher.Name = ((ArrayList)rawEntity)[8].ToString();
                _publisher.Username = ((ArrayList)rawEntity)[9].ToString();
                _publisher.Email = ((ArrayList)rawEntity)[10].ToString();
                _publisher.Member = (bool)((ArrayList)rawEntity)[11];

                _node.PublisherOwner = _publisher;
                _node.TotalViews = int.Parse(((ArrayList)rawEntity)[14].ToString());
                _node.TotalComments = int.Parse(((ArrayList)rawEntity)[15].ToString());

                _transporter.Add(_node);
            }

            _transporter.TotalRecords = dataAccess.getRecordsAfected;
            return _transporter;
        }
    }
}
